package com.example.upload.config;


import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redisson客户端配置
 */
@Configuration
public class RedissonConfig {
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port:16379}")
    private Integer port;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.database}")
    private Integer database;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient (){
        Config config = new Config();
        config.setLockWatchdogTimeout(6*1000L);
        config.setThreads(4);
        String address = String.format("redis://%s:%d", host,port);
        config.useSingleServer()
                .setAddress(address)
                .setPassword(password)
                .setDatabase(database);
        RedissonClient client = Redisson.create(config);
        return client;
    }

}
